package JUnit;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import Servlets.WhatsAppConstatnts;
import protocol.Headers;

public class RemoveUser extends mainTest{
	@Before
	public void setUp() throws Exception {
		_url = "remove_user";
	}
	@Test
	public void test405() {
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"GET /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		assertTrue(response1.contains("HTTP/1.1 " + Headers.STATUS_405));
	}

	@Test
	public void test403() {
		String response1 = this
				.runtest(new RunnableClient(
						"localhost",
						9969,
						"POST /"
								+ _url
								+ ".jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
		assertTrue(response1.contains(Headers.STATUS_403));
	}

	@Test
	public void testERROR_336() {
		String response5 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd&Phone=123456\n$"));
		String cookie2 = this.getCookie(response5);
		String response6 = this.runtest(new RunnableClient("localhost", 9969,
				"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie2
						+ "\n\nList=Groups\n$"));
		assertTrue(response6.contains(WhatsAppConstatnts.ERROR_336));
	}
	
	@Test
	public void testERROR_769_GroupNotFound() {
		String response5 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd&Phone=123456\n$"));
		String cookie2 = this.getCookie(response5);
		String response6 = this.runtest(new RunnableClient("localhost", 9969,
				"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie2
						+ "\n\nTarget=Groups&User=gggg\n$"));
		assertTrue(response6.contains(WhatsAppConstatnts.ERROR_769));
	}
	
	@Test
	public void testERROR_788() {
	String response5 = this
			.runtest(new RunnableClient("localhost", 9969,
					"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd&Phone=123456\n$"));
	String hh = this
			.runtest(new RunnableClient("localhost", 9969,
					"POST /login.jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));
	String cookie2 = this.getCookie(response5);
	String response1 = this.runtest(new RunnableClient("localhost", 9969,
			"POST /create_group.jsp HTTP/1.1\nCookie: " + cookie2 + "\n\n"
					+ WhatsAppConstatnts.GROUP_NAME
					+ "=TestGroup1&Users=userToAdd,yochailehman2\n$"));
	String response6 = this.runtest(new RunnableClient("localhost", 9969,
			"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie2
					+ "\n\nTarget=TestGroup1&User=gggg\n$"));
	assertTrue(response6.contains(WhatsAppConstatnts.ERROR_788));
	}
	
	@Test
	public void testERROR_668() {
	String response5 = this
			.runtest(new RunnableClient("localhost", 9969,
					"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd&Phone=123456\n$"));
	this
			.runtest(new RunnableClient("localhost", 9969,
					"POST /login.jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));

	String cookie2 = this.getCookie(response5);
	
	
	String response7 = this
			.runtest(new RunnableClient("localhost", 9969,
					"POST /login.jsp HTTP/1.1\n\nUserName=testUser&Phone=1234456\n$"));
	String cookie = this.getCookie(response7);
	this.runtest(new RunnableClient("localhost", 9969,
			"POST /create_group.jsp HTTP/1.1\nCookie: " + cookie2 + "\n\n"
					+ WhatsAppConstatnts.GROUP_NAME
					+ "=TestGroup1&Users=userToAdd,yochailehman2\n$"));
	String response6 = this.runtest(new RunnableClient("localhost", 9969,
			"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie
					+ "\n\nTarget=TestGroup1&User=yochailehman2\n$"));
	assertTrue(response6.contains(WhatsAppConstatnts.ERROR_668));
	}
	
	
	@Test
	public void testERROR_668_userRemoved() {
		String response5 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd&Phone=123456\n$"));
		this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));

		String cookie2 = this.getCookie(response5);
		
		this
		.runtest(new RunnableClient("localhost", 9969,
				"POST /login.jsp HTTP/1.1\n\nUserName=user1&Phone=123\n$"));
		this
		.runtest(new RunnableClient("localhost", 9969,
				"POST /login.jsp HTTP/1.1\n\nUserName=user2&Phone=1234\n$"));
		this
		.runtest(new RunnableClient("localhost", 9969,
				"POST /login.jsp HTTP/1.1\n\nUserName=user3&Phone=12345\n$"));
		
		String response7 = this
				.runtest(new RunnableClient("localhost", 9969,
						"POST /login.jsp HTTP/1.1\n\nUserName=testUser&Phone=1234456\n$"));
		String cookie = this.getCookie(response7);
		this.runtest(new RunnableClient("localhost", 9969,
				"POST /create_group.jsp HTTP/1.1\nCookie: " + cookie + "\n\n"
						+ WhatsAppConstatnts.GROUP_NAME
						+ "=TestGroup1&Users=user1,user2,userToAdd,testUser\n$"));
		String response6 = this.runtest(new RunnableClient("localhost", 9969,
				"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie
						+ "\n\nTarget=TestGroup1&User=1234\n$"));
		assertTrue(response6.contains("1234 removed from TestGroup1"));
		String response88 = this.runtest(new RunnableClient("localhost", 9969,
				"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie
						+ "\n\nTarget=TestGroup1&User=1234\n$"));
		assertTrue(response88.contains(WhatsAppConstatnts.ERROR_788));
	}
	
	
	@Test
	public void test() {
	String response5 = this
			.runtest(new RunnableClient("localhost", 9969,
					"POST /login.jsp HTTP/1.1\n\nUserName=userToAdd&Phone=123456\n$"));
	this
			.runtest(new RunnableClient("localhost", 9969,
					"POST /login.jsp HTTP/1.1\n\nUserName=yochailehman2&Phone=0546861622\n$"));

	String cookie2 = this.getCookie(response5);
	
	this
	.runtest(new RunnableClient("localhost", 9969,
			"POST /login.jsp HTTP/1.1\n\nUserName=user1&Phone=123\n$"));
	this
	.runtest(new RunnableClient("localhost", 9969,
			"POST /login.jsp HTTP/1.1\n\nUserName=user2&Phone=1234\n$"));
	this
	.runtest(new RunnableClient("localhost", 9969,
			"POST /login.jsp HTTP/1.1\n\nUserName=user3&Phone=12345\n$"));
	
	String response7 = this
			.runtest(new RunnableClient("localhost", 9969,
					"POST /login.jsp HTTP/1.1\n\nUserName=testUser&Phone=1234456\n$"));
	String cookie = this.getCookie(response7);
	this.runtest(new RunnableClient("localhost", 9969,
			"POST /create_group.jsp HTTP/1.1\nCookie: " + cookie + "\n\n"
					+ WhatsAppConstatnts.GROUP_NAME
					+ "=TestGroup1&Users=user1,user2,userToAdd,testUser\n$"));
	String response6 = this.runtest(new RunnableClient("localhost", 9969,
			"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie
					+ "\n\nTarget=TestGroup1&User=1234\n$"));
	assertTrue(response6.contains("1234 removed from TestGroup1"));
	
	this.runtest(new RunnableClient("localhost", 9969,
				"POST /add_user.jsp HTTP/1.1\nCookie: " + cookie
						+ "\n\nTarget=TestGroup1&User=1234\n$"));
	String response88 = this.runtest(new RunnableClient("localhost", 9969,
			"POST /" + _url + ".jsp HTTP/1.1\nCookie: " + cookie
					+ "\n\nTarget=TestGroup1&User=1234\n$"));
	assertTrue(response88.contains("1234 removed from TestGroup1"));
	}
	
}
